<template>
  <div class="tabbar">
    <!-- 导航栏左边区域 -->
    <div class="logo">
      <img src="~assets/img/newest/R-C (1).jpg"
           alt=""
           @click="backHome()">
      <div class="title"
           @click="backHome()">哆啦音乐</div>
      <div class="back"
           @click="back()">
        <img src="~assets/img/content/back.svg"
             alt="">
      </div>
    </div>
    <!-- 导航栏搜索区域 -->
    <music-search />
    <!-- 导航栏右边登录区域,最小化，还原，推出 -->
    <div class="content">
      <!-- 登陆 -->
      <div class="logins"
           @mouseenter="showNav()"
           @mouseleave="hiddenNav()">
        <div @click="showLogin()"
             class="login">
          <div class="profile">
            <img :src="getAvatar"
                 alt="">
          </div>
          <div>{{getUserName}}</div>
        </div>

        <!-- 登陆后显示的小方块 -->
        <div class="show"
             ref="isShowNav">
          <ul>
            <li @click="myHome()"><i class="iconfont icon-wo"></i> 我的主页</li>
            <li @click="logout()"><i class="iconfont icon-tuichu"></i> 退出</li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { _logout } from 'network/user'
import MusicSearch from '../search/MusicSearch'
export default {
  name: 'TabBar',
  components: {
    MusicSearch
  },
  data () {
    return {
      image: "",
      statu: '未登录',
      isShow: false,
      isShownav: ''
    }
  },
  mounted () {
    this.isShownav = this.$store.getters.getCookie;
  },
  computed: {
    // 动态设置登录后的头像
    getAvatar () {
      return this.$store.getters.getAvatar;
    },
    // 根据登录，显示不同名称
    getUserName () {
      return this.$store.getters.getUserName;
    }
  },
  methods: {
    // 点击回到主页
    backHome () {
      if (this.$route.path === '/discover') return
      this.$router.push("/discover");
    },
    // 返回，回退
    back () {
      this.$router.go(-1)
    },
    // 点击显示登录界面
    showLogin () {
      this.$store.commit("showLogin");
    },
    // 登陆后显示菜单栏
    showNav () {
      if (this.isShownav != '') {
        this.$refs.isShowNav.style.display = 'block';
      }
    },
    hiddenNav () {
      if (this.isShownav) {
        this.$refs.isShowNav.style.display = 'none';
      }
    },
    myHome () {
      this.$router.push('/myhome');
    },
    logout () {
      localStorage.clear('cookie');
      // 强制刷新页面
      window.location.reload(true);
    }
  }
}
</script>
<style scoped>
.tabbar {
  height: 54px;
  width: 100%;
  box-sizing: border-box;
  background-color: #00aa85;
}
.logo {
  cursor: pointer;
  height: 100%;
  width: 20%;
  line-height: 100%;
  display: flex;
  float: left;
  align-items: center;
  position: relative;
}
.back {
  display: inline-block;
  height: 26px;
  position: absolute;
  right: 5px;
  opacity: 0.6;
}
.back:hover {
  opacity: 1;
}
.back img {
  height: 100% !important;
}
.content {
  width: 20%;
  float: right;
  height: 100%;
  display: flex;
  position: relative;
}
.logins {
  width: 50%;
  height: 100%;
}
.login {
  cursor: pointer;
  float: left;
  margin-right: 50px;
  display: flex;
  align-items: center;
  position: relative;
  top: 15px;
}
.profile {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background-color: #fff;
  margin-right: 10px;
}
.profile img {
  width: 100%;
  border-radius: 50%;
}
.logo img {
  margin: 0px 10px 0px 10px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}
/* 登陆后的小界面 */
.show {
  width: 130px;
  background-color: #eee;
  position: absolute;
  top: 45px;
  left: -10%;
  z-index: 2;
  font-size: 14px;
  padding-left: 10px;
  box-sizing: border-box;
  display: none;
}
.show li {
  padding: 5px 0;
  height: 5%;
  list-style: none;
  color: #000;
}
.show li:hover {
  background: rgb(182, 182, 182) !important;
}
</style>
